
*** HOUSEHOLD CONTROLS COLLECTED AT 11 

use "Data/NCDS/UKDA-5565-stata11/stata11/ncds0123.dta", clear
label variable n2region "2P Region at NCDS1 (1965) - 7 years"
qui ds, not(varl "ncdsid serial number"|varl "2P*" |varl "2M*")
drop `r(varlist)'

label define nym 0 "No" 1 "Yes" 99 "Missing", replace

* rename serial number
rename ncdsid  NCDSID  

* region at 11 (missing coded as 99)
rename n2region region_11
recode region_11 (-1=99) (.=99)
label define n2region  3 "E and W Riding" 99 "Missing", modify
label values region_11 n2region

* kids in hh (under 21)
rename n1117 ikidshh_11
recode ikidshh_11 (-1=.)
winsor ikidshh_11, generate(kidshh_11) p($p_winsior)
drop ikidshh_11
label variable kidshh_11 "Number of children aged under 21 in the household" 
ge MissingKH_11=kidshh_11==.
label variable MissingKH_11 "Missing number of children aged under 21 in the household"
su kidshh_11
replace kidshh_11=r(mean) if MissingKH_11==1

* parents was child to stay on in education
rename  n1136 parentwanted_11
recode parentwanted_11 (-1 .=99) (1=0) (2=1) (3=2)
label define pw11 0 "No" 1 "Yes" 2 "Don't know" 99 "Missing"
label values parentwanted_11 pw11

* mother goes on outings with child
rename n1145 motheroutings_11
recode motheroutings_11 (-1 4 .=99) 
label define n1145 99 "Missing", modify
label define n1145  1 "Most weeks", modify
label define n1145  2 "Occasionally", modify
label define n1145  3 "Never or hardly ever", modify
label values motheroutings_11 n1145


* father goes on outings with child
rename n1146 fatheroutings_11
recode fatheroutings_11 (-1 4 .=99) 
label define n1146 99 "Missing", modify
label define n1146  1 "Most weeks", modify
label define n1146  2 "Occasionally", modify
label define n1146  3 "Never or hardly ever", modify
label values fatheroutings_11 n1146


* dad's role in managing the child
rename n1147 dadsrole_11
recode dadsrole_11 (-1 . 4 5=99)
label define n1147 99 "Missing", modify
label define n1147 1 "Father's role bigger or equal", modify
label define n1147 2 "Father's role smaller but significant", modify
label define n1147 3 "Father's role very small or zero", modify
label values dadsrole_11 n1147


* housing tenure (owned, rented, council house, etc.)
rename n1152 housetenure_11
recode  housetenure_11 (-1 . 6 =99) (4=3) (5=6) (.=99) 
label define n1152 3 "Private rented" 99 "Missing", modify
label values housetenure_11 n1152

* rooms in house (excluding kitchen and bathrooms)
rename n1156 iroomsinhouse_11
replace iroomsinhouse_11=. if iroomsinhouse_11<0
winsor iroomsinhouse_11, generate(roomsinhouse_11) p($p_winsior)
drop iroomsinhouse_11
label variable roomsinhouse_11 "Number of rooms in the home" 
ge MissingRH_11=roomsinhouse_11==.
label variable MissingRH_11 "Missing number of rooms in the home"
su roomsinhouse_11
replace roomsinhouse_11=r(mean) if MissingRH_11==1

* social class of father 
rename  n1171  fathersc_11
recode fathersc_11 (-1 . 8=99) (6=5) (7=6)
replace  fathersc_11=7 if n1172==1
label define fsc11  1 "I" 2 "II" 3 "IIIN" 4 "IIIM " 5 "IV" 6 "V" 7 "Mother single" 99 "Missing", replace
label values fathersc_11 fsc11

* mum has worked since the child was age 7
rename n1212 mumwork_11 
recode mumwork_11 (-1 . 3 4=99) (2=0)
label values mumwork_11 nym
label variable mumwork_11 "Mother has worked since child was 7"

* mum's work in the last year
rename n1218 wkft1
rename n1215 wkft2
rename n1224 wkpt1
rename n1221 wkpt2
egen rmax=rowmax(wk*)
ge mumwklastyr_11=0 if rmax<=0
replace mumwklastyr_11=99 if rmax==.
replace mumwklastyr_11=0 if mumwork_11==0
recode wkft1 wkft2 wkpt1 wkpt2  (-1 .=0)
ge wkft=wkft1+wkft2
ge wkpt=wkpt1+wkpt2
ge sft=wkft/(wkft+wkpt)
replace mumwklastyr_11=1 if sft>0.5  &  sft!=. & mumwklastyr_11==.
replace mumwklastyr_11=2 if sft<=0.5 &  sft!=. & mumwklastyr_11==.
replace mumwork_11=1 if mumwklastyr_11==1|mumwklastyr_11==2
replace mumwklastyr_11=99 if mumwork_11==99
label define mw11 0 "Has not worked" 1 "Mostly full-time" 2 "Mostly part-time" 99 "Missing"
label values mumwklastyr_11 mw11

* SC of mum's most recent work
ge SCmum_11=.
replace SCmum_11=1 if  n1225==1|n1225==2
replace SCmum_11=3 if  n1225==3|n1225==4|n1225==5|n1225==9
replace SCmum_11=5 if  n1225==6|n1225==7|n1225==8|n1225==10
replace SCmum_11=6 if  mumwork_11==0
replace SCmum_11=99 if mumwork_11==99
replace SCmum_11=5 if mumwork_11==1 & SCmum_11==.
label define msc11 1 "I or II" 3 "IIIN or IIIM" 5 "IV or V" 6 "Mother has not worked since child was 7" 99 "Missing"
label values SCmum_11 msc11


* financial difficulities
rename n1230 financialdiff_11
recode financialdiff_11 (. -1 3 4 5=99) (2=0) 
label values financialdiff_11 nym

* free school meals
rename n1229 FSM_11
recode FSM_11 (-1 . 3 4=99) (2=0)
label values FSM_11 nym

********************************************************************************
* Variables collected from a medical examination by a doctor
********************************************************************************

* speech
rename n1544 speech_11
recode speech_11 (-1 4 .=99) (3=2)
label define n1544 99 "Missing" 1 "Normal" 2 "Deficient", modify

* hearing
rename n1553 hearing_11
recode hearing_11 (-1 . 4 5=99) (3=2) 
label define n1553 99 "Missing" 1 "Normal" 2 "Deficient", modify

* vision
rename n1567 vision_11
recode vision_11 (-1 . 4=99) (3=2) 
label define n1567  99 "Missing" 1 "Normal" 2 "Deficient", modify


* Generate labeled indicators
local catvar region_11 parentwanted_11 motheroutings_11 fatheroutings_11 dadsrole_11 housetenure_11 fathersc_11 ///
mumwork_11 mumwklastyr_11 financialdiff_11 FSM_11 hearing_11 vision_11 speech_11 SCmum_11
foreach r of local catvar{
	indicators `r'
}

keep NCDSID *_11* 
sort NCDSID 

save scratchdata/ncds0123_HDcontrols11.dta, replace

